Skip to content

Keep the control socket in a private folder - #62

Merged
beetlebugorg merged 3 commits into
mainfrom
private-socket-dir
Nov 28, 2026
Merged

beetlebugorg merged 3 commits into
mainfrom
private-socket-dir

Conversation

@beetlebugorg

Copy link
Copy Markdown
Owner

Part of #15.

Without XDG_RUNTIME_DIR, or when that folder is not a private folder of the user, the control socket of the preview went to /tmp/dockyard-UID-HASH.sock. It now goes to dockyard/run below XDG_STATE_HOME or ~/.local/state on Linux, and below ~/Library/Caches on macOS. sock.privateDir makes that folder (mode 0700) and checks it: a folder, not a link, of the user, with no rights for others. sock.connect connects only to a socket file of the user that is not a link. host.controlPath takes the folders of the environment (host.Dirs), so the window, the preview child, and dockyard --mcp compute the same path from the same environment.

Local checks: aarch64-macos and x86_64-windows builds pass. In the last test run, 26 passed and 2 failed. One failure was the --mcp test, whose child had no HOME; the last commit gives it the HOME of the test, and that fix is not run locally because builds are paused on this host. The other failure was the exec event of a short program in the helper test: it also fails on other branches under the load of this host, and the helper is unchanged here.

@beetlebugorg beetlebugorg added this to the Sandbox milestone Nov 27, 2026
@beetlebugorg

Copy link
Copy Markdown
Owner Author

Windows test result: failure at compile time of the test step.

Command (in a checkout of cc7dbe9, Zig 0.17.0, x86_64-windows):

zig build install test --summary line

The test "the control path depends on the project folder" in src/app/host.zig calls std.c.getenv (and std.c.getpid), and the Windows test build does not link libc:

test
+- run test
   +- compile test debug native 1 errors
lib\std\c.zig:11142:12: error: dependency on libc must be explicitly specified in the build command
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
           ^~~
referenced by:
    test.the control path depends on the project folder: src\app\host.zig:312:27
    host: src\tests.zig:12:22
    1 reference(s) hidden; use '-freference-trace=3' to see all references
error: 1 compilation errors

Build Summary: 64/67 steps succeeded (1 failed)

The source line:

    const base = if (std.c.getenv("TMPDIR")) |t| std.mem.sliceTo(t, 0) else "/tmp";
    const home = try std.fmt.allocPrint(a, "{s}/dockyard-test-home-{d}", .{ base, std.c.getpid() });

@beetlebugorg

Copy link
Copy Markdown
Owner Author

macOS QA ran this PR at cc7dbe9 on macOS 27 on an Apple M1.

test log:

error: 'tests.test.the terminal pane runs the agent program in the project folder' failed:
       src/tests.zig:209:9: 0x1040a58e7 in waitIn (test)
               return error.TestExpectedEqual;
       src/tests.zig:194:9: 0x1040a6cb7 in waitFor (test)
       src/tests.zig:242:5: 0x1040a73cb in test.the terminal pane runs the agent program in the project folder (test)
           try r.waitFor(sh("dockyard-42 in /tmp/dockyard-test-", "dockyard-42 in "));
Build Summary: 66/68 steps succeeded (1 failed); 25/30 tests passed (4 skipped, 1 failed)

test2 log:

error: 'tests.test.the terminal pane runs the agent program in the project folder' failed:
       src/tests.zig:209:9: 0x101ed18e7 in waitIn (test)
               return error.TestExpectedEqual;
       src/tests.zig:194:9: 0x101ed2cb7 in waitFor (test)
       src/tests.zig:242:5: 0x101ed33cb in test.the terminal pane runs the agent program in the project folder (test)
           try r.waitFor(sh("dockyard-42 in /tmp/dockyard-test-", "dockyard-42 in "));
Build Summary: 66/68 steps succeeded (1 failed); 25/30 tests passed (4 skipped, 1 failed)

On macOS, /tmp is a link to /private/tmp, so pwd in the shell prints /private/tmp/... and the test looks for /tmp/... This does not come from this PR. main at f33ed61 fails the same test on this Mac (see #60).

Without a private XDG_RUNTIME_DIR the socket goes to dockyard/run below
the state folder (Linux) or ~/Library/Caches (macOS), a folder of mode
0700 that dockyard makes and checks. A client connects only to a socket
file of its user that is not a link.
The test home folder is /tmp/dockyard-test-home-PID when TMPDIR is not
set. The socket path then starts with "/tmp/dockyard-", and the old
check of that prefix failed. The test now checks that the socket is not
in /tmp itself and that it is below the home folder. It also removes
the home folder at the end.
@beetlebugorg

Copy link
Copy Markdown
Owner Author

The branch is now on main (0aa6a53). The rebase had one conflict in src/tests.zig: main put the else line of the test environment in the format of zig fmt, and this PR changed HOME on that line. The resolved line has the HOME of this PR in the new format.

The failure of "the control path depends on the project folder" was in the test, and the rebase did not cause it. When TMPDIR is not set, the test home folder is /tmp/dockyard-test-home-PID. So the socket path is /tmp/dockyard-test-home-PID/.local/state/dockyard/run/dockyard-HASH.sock, and that path starts with /tmp/dockyard-, the prefix that the test rejects. The code was correct. Commit 0d9209f changes the check: the folder of the socket is not /tmp, and on Linux and macOS the socket is below the test home folder. The test also removes that home folder at the end.

Local run on Linux: zig build test-bin, then zig-out/bin/test: 29 passed, 3 skipped, 0 failed.

@beetlebugorg

Copy link
Copy Markdown
Owner Author

Windows test result on 0d9209f: the same compile error as on cc7dbe9, in the test step.

Commands (Zig 0.17.0, x86_64-windows; the test command with an emptied cache):

zig build install --summary line
zig build test --summary all

zig build install passed (63/63 steps). zig build test stops here:

test
+- run test
   +- compile test debug native 1 errors
lib\std\c.zig:11142:12: error: dependency on libc must be explicitly specified in the build command
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
           ^~~
referenced by:
    test.the control path depends on the project folder: src\app\host.zig:312:27
    host: src\tests.zig:12:22
error: 1 compilation errors

Build Summary: 65/68 steps succeeded (1 failed)

The Windows build of the tests has no libc, so std.c.getenv and
std.c.getpid do not compile there. On Windows the control path does not
use the home folder, so the test uses a plain name.
@beetlebugorg
beetlebugorg merged commit f884a88 into main Nov 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant